package define;

public enum Keyword 
{
	E_ESC_KEY(-1, '\\'),
	
	E_FUN_START_KEY(-10, '@', -11),
	E_FUN_END_KEY(-11, '#'),
	E_VARIABLE_KEY(-13, '$', -13),
	E_CELL_KEY(-14, '|', -14),
	E_FUN_CHILD_START_KEY(-15, '<', -16),
	E_FUN_CHILD_END_KEY(-16, '>'),
	E_WHOLE_WORD_START(-17, '[', -18),
	E_WHOLE_WORD_END(-18, ']'),
	
	E_COMMENT_KEY(-12, '?'),
	
	E_CELL_SPLIT_KEY(-117, '.'),
	E_CELL_ATTR_KEY(-118, '^'),
	E_CELL_EXCEL_KEY(-119, ':'),
	E_CELL_STRING_KEY(-120, '"')
	;
	
	private int m_code;
	private char m_char;
	private int m_relativeCode;
	
	private Keyword(int code, char ch)
	{
		m_code = code;
		m_char = ch;
		m_relativeCode = Config.NO_RELATIVE;
	}
	
	private Keyword(int code, char ch, int relativeCode)
	{
		m_code = code;
		m_char = ch;
		m_relativeCode = relativeCode;
	}
	
	public int getCode()
	{
		return m_code;
	}
	
	public char getChar()
	{
		return m_char;
	}
	
	public int getRelativeCode()
	{
		return m_relativeCode;
	}
	
	public static Keyword isRelative(int code)
	{
		Keyword aim = null;
		Keyword[] values = Keyword.values();
		for(int i = E_FUN_START_KEY.ordinal(), max = E_WHOLE_WORD_END.ordinal(); i <= max; ++i)
		{
			if(code == values[i].getCode())
			{
				aim = values[i];
				break;
			}
		}
		if(aim == null || aim.getRelativeCode() == Config.NO_RELATIVE)
		{
			return null;
		}
		return aim;
	}
	
	public static Keyword isCheck(int ch)
	{
		Keyword[] values = Keyword.values();
		for(int i = E_FUN_START_KEY.ordinal(), max = E_WHOLE_WORD_END.ordinal(); i <= max; ++i)
		{
			if(ch == values[i].getChar())
			{
				return values[i];
			}
		}
		return null;
	}
	
	public static Keyword isExpressCheck(int code)
	{
		Keyword[] values = Keyword.values();
		for(int i = E_FUN_START_KEY.ordinal(), max = E_WHOLE_WORD_END.ordinal(); i <= max; ++i)
		{
			if(code == values[i].getCode())
			{
				return values[i];
			}
		}
		return null;
	}
	
	public static char changeToChar(int code)
	{
		for(Keyword key: Keyword.values())
		{
			if(key.getCode() == code)
			{
				return key.getChar();
			}
		}
		return 0;
	}
}
